package com.example.edu.tips;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * @author yanzhao
 * @date 2022/1/27 10:36
 * @since 1.0.0
 */
public class WordMain {

    private static IWordManageService wordManageService = new WordManageServiceImpl();

    public static void main(String[] args) {
        searchWord();
    }

    private static void searchWord() {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(WordMain.class.getResourceAsStream("/dictionary/1.txt"), StandardCharsets.UTF_8));) {
            String line;
            while ((line = br.readLine()) != null) {
                search(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void searchSingleLetterWord() {
        for (int i = 0; i < 26; i++) {
            search(((char) (i + 'A')) + "");
            search(((char) (i + 'a')) + "");
        }
    }

    private static void search(String prefix) {
        List<Node> list = wordManageService.searchPrefix(prefix);
        for (Node node : list) {
            System.out.println(prefix + "====" + node.word + "====" + node.explain);
        }
    }
}
